//
//  MainCollectionViewCell.m
//  Comic
//
//  Created by Ryan on 16/3/10.
//  Copyright © 2016年 程锦. All rights reserved.
//

#import "MainCollectionViewCell.h"

@implementation MainCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.isStart = 1;
        [self createView];
    }
    return self;
}

- (void)createView{

    self.user_Avatar = [UIImageView new];
    
    self.user_Avatar.backgroundColor = [UIColor blueColor];
    
    self.user_Avatar.layer.cornerRadius = 20;
    
    self.user_Avatar.layer.masksToBounds = YES;
    
    [self.contentView addSubview:self.user_Avatar];
    
    self.user_Login = [UILabel new];
    
    [self.contentView addSubview:self.user_Login];
    
    self.published = [UILabel new];
    self.published.font = [UIFont systemFontOfSize:12];
    self.published.textColor = [UIColor grayColor];
    
    
    
    [self.contentView addSubview:self.published];
    
    self.title = [UILabel new];
    
    self.title.numberOfLines = 0;
    [self.title sizeToFit];
    
    [self.contentView addSubview:self.title];

    self.mp4_ImageView =[UIImageView new];
    
    self.mp4_ImageView.userInteractionEnabled = YES;
    
    self.mp4_ImageView.backgroundColor = [UIColor yellowColor];
    
    [self.contentView addSubview:self.mp4_ImageView];
    

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    
    
    [self.mp4_ImageView addGestureRecognizer:tap];

    self.tags_Label = [UILabel new];
    
    self.tags_Label.font = [UIFont systemFontOfSize:15];
    
    self.tags_Label.textColor = [UIColor lightGrayColor];
    
    [self.contentView addSubview:self.tags_Label];
    
    
    [self.user_Avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(10);
        make.width.height.mas_equalTo(40);
        make.right.mas_equalTo(self.user_Login.mas_left).offset(-10);
        make.bottom.mas_equalTo(self.title.mas_top).offset(-10);

        
        
    }];

    [self.user_Login mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.right.mas_equalTo(10);
        
        make.height.mas_equalTo(20);
        
        
    }];
   
    
    
    [self.published mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.user_Avatar.mas_right).offset(10);
        make.top.mas_equalTo(self.user_Login.mas_bottom).offset(5);
        
    }];

    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(self.mp4_ImageView.mas_top).offset(-10);
        
    }];

    [self.mp4_ImageView mas_makeConstraints:^(MASConstraintMaker *make) {
     
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);

        make.bottom.mas_equalTo(self.tags_Label.mas_top).offset(-10);
        
    }];
    

    
    [self.tags_Label mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-5);
        
        
        
    }];
    


}



- (void)tap:(UITapGestureRecognizer *)tap{
    
    
    
    [[VideoPlayer shareInstance].playerLayer removeFromSuperlayer];
    [[VideoPlayer shareInstance].backView removeFromSuperview];
    [[VideoPlayer shareInstance].rePlay setHidden:YES];
    [[VideoPlayer shareInstance].maskView removeFromSuperview];
    [[VideoPlayer shareInstance].activity stopAnimating];
    
    [[VideoPlayer shareInstance] playWithURL:_url insert:self.mp4_ImageView];
    
//    [self.mp4_ImageView addSubview:[VideoPlayer shareInstance]];

}





@end
